// 住院收费
<template>
  <el-row class="hospitalizedCharge-content" >
    <el-col :span="24">
      <el-col
        :span="24"
        class="pddTop hospitalizedCharge-right"
        style="padding: 0 10px; padding-top: 10px;overflow:hidding;min-height:75vh"
      >
    
        <div
          style="height: 75vh;
    overflow: auto;"
        >
 

          <ViewTitle text="入院信息" id="ruyuan"  />
          <el-col :span="24" class="pddTop10" @click='hospitalization2'>
            <el-form
              :inline="false"
              class="form-demo"
              label-width="150px"
              v-model="menfrom"
            >
              <el-col :span="24">
               
               <el-col :span="8">
                  <el-form-item label="人员编号:">
                    <el-input
                      placeholder="人员编号"
                      v-model="menfrom.psn_no"
                      
                      :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                 <el-col :span="8">
                  <el-form-item label="险种类型:">
                    <!-- <el-select
                      v-model="menfrom.insutype"
                      placeholder="险种类型"
                       :disabled='ifxiu'
                    >
                      <el-option
                        v-for="(item, index) in xianzhong"
                        :key="index"
                        :label="item.name"
                        :value="item.value"
                        @change="xianxuan"
                        >{{ item.name }}</el-option
                      >
                    </el-select> -->
                      <el-select
                      v-model="menfrom.insutype"
                      placeholder="险种类型"
                    >
                      <el-option
                        v-for="(item, index) in xianzhong"
                        :key="index"
                        :label="item.name"
                        :value="item.value"
                         @change="xianxuan"
                        >{{ item.name }}</el-option
                      >
                    </el-select>
                  </el-form-item>
                </el-col>
                  <el-col :span="8">
                  <el-form-item label="联系人姓名:">
                    <el-input
                      placeholder="联系人姓名"
                      v-model="menfrom.coner_name"
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系方式:">
                    <el-input
                      placeholder="联系方式"
                      v-model="menfrom.tel"
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="入院时间:">
                    <el-date-picker
                      v-model="menfrom.begntime"
                       :disabled='ifxiu'
                      type="date"
                      placeholder="选择日期"
                      format="yyyy 年 MM 月 dd 日"
                      value-format="yyyy-MM-dd"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="住院号:">
                    <el-input placeholder="住院号"
                     :disabled='ifxiu' v-model="menfrom.ipt_no">
                    </el-input>
                  </el-form-item>
                </el-col>
                  <el-col :span="8">
                  <el-form-item label="病历号:">
                    <el-input placeholder="病历号"
                     :disabled='ifxiu' v-model="menfrom.medrcdno">
                    </el-input>
                  </el-form-item>
                </el-col>
             
              
                <el-col :span="8">
                  <el-form-item label="就诊凭证类型:">
                    <el-select
                      v-model="menfrom.mdtrt_cert_type"
                      placeholder="就诊凭证类型"
                       :disabled='ifxiu'
                    >
                      <el-option
                        v-for="(item, index) in jiuzhen"
                        :key="index"
                        :label="item.name"
                        :value="item.value"
                        >{{ item.name }}</el-option
                      >
                    </el-select>
                  </el-form-item>
                </el-col>
                     <el-col :span="8">
                  <el-form-item label="就诊凭证编号:">
                    <el-input
                      placeholder="就诊凭证编号"
                      v-model="menfrom.mdtrt_cert_no"
                      
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
               
              </el-col>
     
            
              <el-col :span="24">
          
                    <el-col :span="8">
                  <el-form-item label="医疗类别:">
                    <el-select
                      v-model="menfrom.med_type"
                      placeholder="医疗类别"
                       :disabled='ifxiu'
                    >
                      <el-option
                        v-for="(item, index) in yiliao"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                        >{{ item.name }}</el-option
                      >
                    </el-select>
                    
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="主治医生编码:">
                    <el-input
                      placeholder="主治医生编码"
                      v-model="menfrom.atddr_no"
                      
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="主治医师姓名:">
                    <!-- <el-input
                      placeholder="主治医师姓名"
                      v-model="menfrom.chfpdr_name"
                      
                       :disabled='ifxiu'
                    >
                    </el-input> -->
                       <div class="yisheng">
                      <el-popover
                        placement="bottom-end"
                        v-model="visiblePatient"
                        trigger="focus"
                      >
                        <el-input
                          placeholder="姓名"
                          slot="reference"
                          v-model="menfrom.chfpdr_name"
                          size="mini"
                          style="height:40px"
                        >
                     
                        </el-input>
                        <el-table
                          @row-click="xuanzePatient"
                          height="300"
                          :data="
                            duserlist.filter(
                              data =>
                                !menfrom.chfpdr_name ||
                                data.real_name
                                  .toLowerCase()
                                  .includes(menfrom.chfpdr_name.toLowerCase())
                            )
                          "
                        >
                          <el-table-column
                            width="100"
                            property="number"
                            label="序号"
                          ></el-table-column>

                          <el-table-column
                            width="150"
                            property="real_name"
                            label="姓名"
                          ></el-table-column>
                          <el-table-column
                            width="100"
                            property="dept_name"
                            label="科室"
                          ></el-table-column>

                          <el-table-column
                            width="50"
                            property="gender"
                            label="性别"
                          >
                          <template slot-scope="scope">
       {{scope.row.gender===1?'男':scope.row.gender===2?'女':'未知'}}
      </template>
                          </el-table-column>

                      
                        </el-table>
                      </el-popover>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="入院诊断描述 :">
                    <el-input placeholder="入院诊断描述" 
                     :disabled='ifxiu' v-model="menfrom.adm_diag_dscr">
                    </el-input>
                  </el-form-item>
                </el-col>
                 <el-col :span="8">
                  <el-form-item label="入院科室编码:">
                    <el-input
                      placeholder="入院科室编码"
                      v-model="menfrom.adm_dept_codg"
                      
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
              
                
                      <el-form-item label="入院科室:">
                    <el-cascader
                      v-model="menfrom.department_id"
                      :options="departmentoptions"
                      :props="{ label: 'name', value: 'id' }"
                      style="width:90%"
                      ref="cascaderAddr"
                      :show-all-levels="false"
                      @change="handleChange"
                    ></el-cascader>
                  </el-form-item>
                </el-col>
             
          
              
                <el-col :span="8">
                  <el-form-item label="入院床位:">
                    <el-input placeholder="入院床位"
                     :disabled='ifxiu' v-model="menfrom.adm_bed" >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="住院主诊断代码:">
                    <el-input
                      placeholder="住院主诊断代码"
                      v-model="menfrom.dscg_maindiag_code"
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                 </el-col>
                 <el-col :span="8">
                  <el-form-item label="住院主诊断名称:">
                    <el-input
                      placeholder="住院主诊断名称"
                      v-model="menfrom.dscg_maindiag_name"
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                  
                </el-col>
               
                 
                  <el-col :span="8">
                 <el-form-item label="出院方式">
            <el-select v-model="menfrom.leave_way" placeholder="出院方式">
              <el-option
                v-for="(item, index) in chuyuanfangshi"
                :key="index"
                :label="item.name"
                :value="item.id"
                >{{ item.name }}</el-option
              >
            </el-select>
          </el-form-item>
                  
                </el-col>
               
                <el-col :span="24">
                  <el-form-item label="主要病情描述:">
                    <el-input
                      placeholder="主要病情描述"
                      v-model="menfrom.main_cond_dscr"
                       :disabled='ifxiu'
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                 <el-col :span="24">
                   <el-table
      :data="disease"
      style="width: 100%">
     
      <el-table-column
        prop="disease_name"
        label="名称"
       >
      </el-table-column>
      <el-table-column
        prop="disease_number"
        label="编号">
      </el-table-column>
    </el-table>
                </el-col>
              </el-col>
            </el-form>
          </el-col>
      
        </div>
      </el-col>
    </el-col>
  
  </el-row>
</template>
<script>
import FromList from "@/forComponents/fromList/fromList";
import TopManu from "@/components/TopMenu";
import ViewTitle from "@/forComponents/viewTitle/index.vue";
import {
  handelMemberSave,
  getProfileList,
  getdictIndex,
  hospitalization,
  getgetDiseaseDict,
  getHospitalMember
} from "@/api/register";
import { getIndex,} from "@/api/account";
import { getOrgInfo, update,getHospitalDetail, } from "@/api/zhuyanre";

import { getUserList } from "@/api/user";
import { getOrganization } from "@/api/organization";
import { getMemberIndex } from "@/api/patient";

let that;
export default {
    props: ['patientinfo'],
    // patientinfo: {
    //   type: Object,
    //   default: 0
    // }
  // },
  data() {
    return {
         
   
      //提交
      menfrom: {
        id:'',
        psn_no:'',//人员编号
        insutype:'',//险种类型
        coner_name:'',//联系人姓名，
        tel:'',//联系电话
        begntime:'',//时间
        mdtrt_cert_type:'',//就诊凭证类型
        mdtrt_cert_no:'',//就诊凭证编号
        med_type:'',//医疗类别
        ipt_no:'',//住院号
        atddr_no:'',//主治医生编码
        chfpdr_name:'',//主治医生
        adm_diag_dscr:'',//入院诊断描述
        adm_dept_codg:'',//入院科室编码
        adm_dept_name:'',//入院科室名称
        adm_bed:'',//入院床位
        dscg_maindiag_code:'',//  住院主诊断代码
        dscg_maindiag_name:'',//住院主诊断名称 
        main_cond_dscr:'',//主要病情描述
        dise_codg:'',//病种编码
        dise_name:'',//病种名称
        dise_type_code:'',
        oprn_oprt_code:'',//手术操作代码
        oprn_oprt_name:'',//
        department_id:'',
      
        leave_way:[],
      },
      xianzhong:[],
      yiliao:[],
      jiuzhen:[],
      disease:[
        {}
      ],
      chuyuanfangshi:[],
      departmentoptions:[],
      ifxiu:false,
           visiblePatient:false,
     duserlist:[],
  
    selectData1:[],     
    };
  },

  mounted() {
    that = this;
  this.getdiet_list()
  this.getOrganization()
  this.getinfo(this.patientinfo.id)
  this.getIndex()
  this.daiyuinfo()
  },
  watch: {
    patientinfo(to) {
      that.patientinfo=to
     that.getinfo(that.patientinfo.id)
    },
   
  },
  methods: {
    xianxuan(val){
        console.log(val)
    },
    getinfo(id){
         getHospitalDetail({id:id}).then(res=>{
          
           var arr=res.data
           
            // var art=arr.room_name.split('/')[arr.room_name.split('/').lenght-1]
             console.log(arr)
           this.disease=arr.disease_list
      console.log(this.disease.length)
        this.menfrom={
          id:id,
        psn_no:arr.member.psn_no,//人员编号
        insutype:arr.member.insutype,//险种类型
        coner_name:arr.member.name,//联系人姓名，
        tel:arr.member.phone,//联系电话
        begntime:arr.begntime,//时间
        mdtrt_cert_type:arr.mdtrt_cert_type,//就诊凭证类型
        mdtrt_cert_no:arr.mdtrt_cert_no,//就诊凭证编号
        med_type:arr.med_type,//医疗类别
        ipt_no:arr.ipt_no,//住院号
        atddr_no:arr.doctor.atddr_no,//主治医生编码
        chfpdr_name:arr.doctor.chfpdr_name,//主治医生
        adm_diag_dscr:arr.adm_diag_dscr,//入院诊断描述
        adm_dept_codg:arr.dept.code,//入院科室编码
        adm_dept_name:arr.dept.name,//入院科室名称
        department_id:arr.dept.id,
        adm_bed:arr.room_name,//入院床位
        dscg_maindiag_code:this.disease.length!=0?this.disease[0].disease_number:'',//  住院主诊断代码
        dscg_maindiag_name:this.disease.length!=0?this.disease[0].disease_name:'',//住院主诊断名称 
        main_cond_dscr:arr.main_cond_dscr,//主要病情描述
        // dise_codg:'',//病种编码
        // dise_name:'',//病种名称
        // oprn_oprt_code:'',//手术操作代码
        // oprn_oprt_name:'',//
        }
      })
    },
        getOrganization() {
      getOrganization().then(res => {
        console.log(res);
        this.departmentoptions = this.deleteChildren(res.data);
      });
    },
        deleteChildren(arr) {
      let childs = arr;
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children);
          } else {
            delete childs[i].children;
          }
        }
      }
      return arr;
    },
   
     handleChange(e) {
      this.menfrom.adm_dept_codg = this.$refs['cascaderAddr'].getCheckedNodes()[0].data.code
        this.menfrom.adm_dept_name = this.$refs['cascaderAddr'].getCheckedNodes()[0].data.name
      // this.getFathersById(value,this.departmentoptions)
    },
    getFathersById (id, data, prop) {
      var arrRes = []
      const rev = (data, nodeId) => {
        for (var i = 0, length = data.length; i < length; i++) {
          const node = data[i]
          if (node[prop] === nodeId) {
            arrRes.unshift(node[prop])
            return true
          } else {
            if (node.child && node.child.length) {
              if (rev(node.child, nodeId)) {
                arrRes.unshift(node[prop])
                return true
              }
            }
          }
        }
        return false
      }
      rev(data, id)
      return arrRes
    },
         getIndex(){
       var data_y={
         user_type:2,
         page:1,
         limit:3000,
        //  status:1
       }
 
      getIndex(data_y)
      .then(res=>{
         this.duserlist = res.data.list
      })
      .catch(e=>{
    
        this.$message({
          message:e.message,
          type: 'error'
        });
      })
    },
  
        xuanzePatient(item) {
     
    this.menfrom.chfpdr_name=item.real_name
    this.menfrom.atddr_no=item.medical_insurance_number
    this.visiblePatient = false;
    },
  getdiet_list() {
      getdictIndex({ group_id: "13,15,62,51" })
        .then(arr => {
          let data = arr.data;

          data.forEach((item, key) => {
            if(item.id==13){
               
             that.xianzhong=item.items;
            }else if(item.id==15){
            
             that.yiliao=item.items;
            }else if (item.id==62) {
              that.jiuzhen=item.items
            }else if (item.id==61) {
              that.chuyuanfangshi=item.items
            }

            

           
          });
        })
        .catch(e => {});

    },
    //提交住院信息
    hospitalization2() {
      var data = JSON.stringify(that.menfrom);
      this.ifupdata=this.ifxiu
    data=JSON.parse(data)
    data.med_type=that.mapyiliao(
                data.med_type
              );
      // data.insutype=that.mapxian(
      //           data.insutype
      //         );
      //           data.mdtrt_cert_type=that.mapjiuzhen(
      //           data.mdtrt_cert_type
      //         );
        this.$emit("hospitalization2", data, this.ifupdata);

    },
       mapxian(num) {
      var art = "";
      for (var i in that.xianzhong) {
        if (that.xianzhong[i].id == num) {
          art = that.xianzhong[i].value;
           return art;
        }
        console.log(art)
       

      }
    },
       mapyiliao(num) {
         console.log(num,that.yiliao)
      var art = "";
      for (var i in that.yiliao) {
         console.log(that.yiliao[i].id)
        if (that.yiliao[i].id == num) {
          art = that.yiliao[i].value;
          return art;
        }
       
        
      }
    },
       mapjiuzhen(num) {
      var art = "";
      for (var i in that.jiuzhen) {
        if (that.jiuzhen[i].id == num) {
          art = that.jiuzhen[i].value;
          return art;
        }
        
      }
    },
    closeitalization2(){
       this.$emit("closeitalization2");
    
       
    },
      

  },
  components: {
    FromList,
    TopManu,
    ViewTitle
  },

};
</script>

<style lang='scss' scoped>
@import "./index.scss";
</style>